/**
 * Created by stillyuk on 16/5/27.
 */
angular.module('app.core')
    .factory('mockData', function () {
        return {
            get: function (url, option) {
                switch (url) {
                    case 'mock/json/info.json':
                        return {
                            data: info(option)
                        };
                    case 'mock/json/community-board.json':
                        return {
                            data: board(option)
                        };
                    case 'mock/json/community-post.json':
                        return {
                            data: post(option)
                        };
                    case 'mock/json/patient-account.json':
                        return {
                            data: patientAccount(option)
                        };
                    default:
                        break;
                }
            }
        };

        function info(option) {
            var draw = option.draw;
            var start = option.start;
            var length = option.length;

            var listSize = 99;
            var data = [];
            for (var i = 0; i < length; i++) {
                var current = start + i + 1;
                if (current > listSize) {
                    break;
                }
                data[i] = {
                    "id": i,
                    "username": "账号" + current,
                    "userType": "类型" + current,
                    "doctorUsername": "医生" + current,
                    "doctorName": "doc" + current,
                    "createDate": "2016-01-01: 09:30"
                }
            }
            return {
                draw: draw + 1,
                recordsTotal: listSize,
                recordsFiltered: listSize,
                data: data
            }
        }

        function board(option) {
            option = option.data;
            var draw = option[0].value;
            var start = option[3].value;
            var length = option[4].value;


            var listSize = 13;
            var data = [];
            for (var i = 0; i < length; i++) {
                var current = start + i + 1;
                if (current > listSize) {
                    break;
                }
                data[i] = {
                    "id": i,
                    "boardName": i % 2 == 0 ? "热门" : "最新",
                    "allowUserToPost": "是",
                    "icon": 'icon',
                    "boardCount": "内容" + current,
                    "lookCount": "100",
                    "commentCount": 80,
                    "likeCount": 5
                }
            }
            return {
                draw: draw + 1,
                recordsTotal: listSize,
                recordsFiltered: listSize,
                data: data
            }
        }

        function post(option) {
            option = option.data;
            var draw = option[0].value;
            var start = option[3].value;
            var length = option[4].value;


            var listSize = 87;
            var data = [];
            for (var i = 0; i < length; i++) {
                var current = start + i + 1;
                if (current > listSize) {
                    break;
                }
                data[i] = {
                    "id": i,
                    "whichBoard": "热门",
                    "postUser": "用户" + current,
                    "isAnonymous": current % 2 ? '是' : '否',
                    "postContent": "内容" + current,
                    "postPicture": "图片",
                    "scanCount": current,
                    "likeCount": current,
                    "commentCount": current,
                    "postDateTime": current,
                    "deleteByUser": current % 2 ? '是' : '否'
                }
            }
            return {
                draw: draw + 1,
                recordsTotal: listSize,
                recordsFiltered: listSize,
                data: data
            }
        }

        function patientAccount(option) {
            option = option.data;
            var draw = option[0].value;
            var start = option[3].value;
            var length = option[4].value;


            var listSize = 25;
            var data = [];
            for (var i = 0; i < length; i++) {
                var current = start + i + 1;
                if (current > listSize) {
                    break;
                }
                data[i] = {
                    "id": i,
                    "username": "账号" + current,
                    "changePassword": "<a href='#aa'>修改</a>",
                    "userType": "类型" + current,
                    "createDate": "2016-01-01: 09:30"
                }
            }
            return {
                draw: draw + 1,
                recordsTotal: listSize,
                recordsFiltered: listSize,
                data: data
            }
        }

    });